#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./paas/esb/apps/guide/views.py
# Compiled at: 2017-11-16 15:44:28
"""
Tencent is pleased to support the open source community by making 蓝鲸智云(BlueKing) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
"""
import markdown
from markdown.extensions.headerid import HeaderIdExtension
from django.views.generic import View
from django.shortcuts import render
from .utils import mdfile_by_name
from esb.common.decorators import is_user_super
from esb.configs.default import menu_items
menu_active_item = 'user_guide'
PAGES = [
 ('esb_introduction', u'ESB介绍'),
 ('add_new_component', u'组件开发'),
 ('buffet_component', u'组件自助接入'),
 ('use_component', u'组件调用说明'),
 ('component_data', u'组件可用数据'),
 ('cmsi_component_guide', u'CMSI消息组件')]

class Page(View):

    @is_user_super
    def get(self, request, name):
        with open(mdfile_by_name(name)) as (fp):
            md_content = unicode(fp.read(), 'utf-8')
            html_part = markdown.markdown(md_content, extensions=[
             'tables',
             'attr_list',
             'fenced_code',
             HeaderIdExtension(level=1),
             'markdown.extensions.codehilite',
             'markdown.extensions.toc'])
        return render(request, 'guide/page.html', {'pages': PAGES,
           'current_page': name,
           'html_part': html_part,
           'menu_items': menu_items,
           'menu_active_item': menu_active_item
           })
